package com.android.sharecar.activity.config;

import com.android.sharecar.activity.R;

import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView;

/**
 * This activity presents something about this app.
 * @author xinyan
 *@date 2011-9-14
 */
public class AboutActivity extends Activity {
	private static final int DIALOG_SOFTVERSION = 1;
	private static final int DIALOG_CHECKUPDATE = 2;
	private static final int MAX_PROGRESS = 100;

	// members
	private TextView mSoftVersion, mCheckUpdate, mInviteFriend;
	private ProgressDialog mProgressDialog; // used for check updates

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.about);

		mCheckUpdate = (TextView) findViewById(R.id.aboutactivity_tv_checkUpdate);
		mInviteFriend = (TextView) findViewById(R.id.aboutactivity_tv_inviteFriend);
		mSoftVersion = (TextView) findViewById(R.id.aboutactivity_tv_softVersion);

		setListenerForMembers();
	}

	private void setListenerForMembers() {
		mCheckUpdate.setOnTouchListener(new View.OnTouchListener() {

			@Override
			public boolean onTouch(View v, MotionEvent event) {
				if (MotionEvent.ACTION_DOWN == event.getAction()) {
					showDialog(DIALOG_CHECKUPDATE);

				}
				return true;
			}
		});

		mInviteFriend.setOnTouchListener(new View.OnTouchListener() {

			@Override
			public boolean onTouch(View v, MotionEvent event) {
				if (MotionEvent.ACTION_DOWN == event.getAction()) {
					startActivity(new Intent(AboutActivity.this,
							InviteFriendsActivity.class));

				}
				return true;
			}
		});

		mSoftVersion.setOnTouchListener(new View.OnTouchListener() {

			@Override
			public boolean onTouch(View v, MotionEvent event) {
				if (MotionEvent.ACTION_DOWN == event.getAction()) {
					startActivity(new Intent(AboutActivity.this,
							SoftVersionActivity.class));

				}
				return true;
			}
		});
	}

	@Override
	protected Dialog onCreateDialog(int id) {
		switch (id) {
		case DIALOG_CHECKUPDATE:
			mProgressDialog = new ProgressDialog(AboutActivity.this);
			// mProgressDialog.setIcon(R.drawable.alert_dialog_icon);
			mProgressDialog.setTitle(R.string.checkUpdating);
			mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
			mProgressDialog.setMax(MAX_PROGRESS);
			mProgressDialog.setButton(getText(R.string.positive),
					new DialogInterface.OnClickListener() {
						@Override
						public void onClick(DialogInterface dialog,
								int whichButton) {

							/* User clicked Yes so do some stuff */
						}
					});
			mProgressDialog.setButton2(getText(R.string.cancel),
					new DialogInterface.OnClickListener() {
						@Override
						public void onClick(DialogInterface dialog,
								int whichButton) {

							/* User clicked No so do some stuff */
						}
					});
			return mProgressDialog;

		default:
			break;
		}

		return null;
	}

}
